home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- References: <4jkq8h$1it6@useneta1.news.prodigy.com>
- X-Newsreader: MicroDot 1.11beta16 [REGISTERED 000012]
- Mime-version: 1.0
- Content-Type: text/plain; charset=iso-8859-1
- Content-Transfer-encoding: 7BIT
- Path: news.gtn.com!art-line.de
- X-Gateway: ZCONNECT UE uuart.art-line.art-line.de [PolyNet zTOr V5.111 Serie: "retrax"]
- Subject: Re: File Open Problem - Please provide clues
- Message-ID: <xZaQmMD12aUz1@andi.art-line.de>
- Date: Fri, 5 Apr 96 20:52:22 GMT
- From: andi@art-line.de (Andreas Winkelmann)
-
- Hi Steve.
-
- > Hi I'm having problems with opening files which are named
- > after simple numbers:
- > 2
- > 5, etc.
- > The reason for naming them this way is because I'm writing a
- > program in C that increments a number, and then attempts to
- > open the file that's actually named by that number.
- > I get mismatched type errors when using FOPEN:
- > int num;
- > filepointer = FOPEN(num,"r"); or
- > filepointer = FOPEN("num","r");
-
- fopen() accepts as the first argument only a stringpointer. You
- have to convert the number in a string.
-
- char buffer[21];
- FILE *fp;
- int num;
-
- sprintf( (char*)&buffer,"%ld.txt",num);
- fp = fopen( (char*)&buffer, "r" );
-
- > Is there a way to manipulate an integer: store it in integer
- > variables, arrays, etc.., but then use that integer to open
- > a file actually named by that integer?..
- > I was going to name the files:
- > 0.txt, 1.txt, 2.txt,
- > and so forth, but this was even trickier with the string
- > concatenating, (attached ".txt" to it) etc.. so the files
- > are named after numbers simply..
-
-
- -----
- Andreas Winkelmann
-
- E-Mail : andi@art-line.de -- MicroDot V1.11beta16
-
-
-